'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:AdministratorAdminZjzczxCtrl
 * @description
 * # AdministratorAdminZjzczxCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('AdministratorAdminZjzczxCtrl', function($scope, DataService, $rootScope, openApi, Util, $location, $routeParams, FormSubmit) {
        $scope.chooseinfo = function() {
            var relModuleObj = {
                name: "AdministratorAdminZjzczxCtrl",
                selectTab: "select_certificate_by_transfer",
                selectTabContent: "选择证件"
            };
            // 清掉关联的编号
            var params = $scope.param;
            Util.savaParamForReview(params, $routeParams.id);
            Util.savaDataforsearch(relModuleObj);
            $location.path("finance/choosepeople")
        };
        // 底部关联模块类型选框添加
        $scope.sheetObj = {};
        var willReturnList = [{
            key: "是",
            value: 2
        }, {
            key: "否",
            value: 1
        }];
        var willReturnObg = {};
        willReturnObg.sheettitle = "是否转回";
        willReturnObg.tabList = willReturnList
        willReturnObg.callback = function(item) {
            $scope.param.willReturn = item.selectTab
        }
        var dealTypeList = [{
            key: "注销",
            value: 2
        }, {
            key: "转出",
            value: 1
        }];
        var dealTypeObj = {};
        dealTypeObj.sheettitle = "办理类型";
        dealTypeObj.tabList = dealTypeList
        dealTypeObj.callback = function(item) {
            $scope.param.dealType = item.selectTab
            if ($scope.param.dealType == 2) {
                $scope.param.willReturn = 1
            }
        }
        $scope.sheetObj.willReturnObg = willReturnObg;
        $scope.sheetObj.dealTypeObj = dealTypeObj;
        $scope.showSheet = function(type) {
            var sheetObj = $scope.sheetObj[type]
            $scope.sheetObj.type = type
            $scope.sheetObj.tabList = sheetObj.tabList
            $scope.sheetObj.sheettitle = sheetObj.sheettitle
            $scope.sheetObj.ifshowSheet = true
            $rootScope.showMasker = true
        };

        $scope.submit = function() {
            if (!$scope.param.certificateId) {
                Util.Toast("请选择证件编号");
                return;
            }
            if (!$scope.param.transferTarger && $scope.param.dealType == 1) {
                Util.Toast("请填写接收单位");
                return;
            }
            if ($scope.param.willReturn == 2 && $scope.param.dealType == 1) {
                if (!$scope.param.returnDate) {
                    Util.Toast("请选择预计转回日期");
                    return;
                }
            }
            if (!$scope.param.willReturn && $scope.param.dealType == 1) {
                Util.Toast("请选择是否转回");
                return;
            }
            if (!$scope.param.dealType) {
                Util.Toast("请选择办理类型");
                return;
            }

            // 提交
            var urlParam = "?operationId=-2" + "&&processId=" + $routeParams.id + "&&url=" + openApi.certificateTransfer
            var options = {};
            options.urlParam = urlParam;
            var myDest = {};
            options.param = angular.copy($scope.param, myDest);
            var TVtype;
            TVtype = Util.getTVType(); //根据页面的来源来判断是发起的流程还是修改的流程，如果是发起的则不管，如果是修改的则获取数据用来回显
            // 如果是修改页面的话则提交的地址不一样，参数一样
            if (TVtype == Util.UPDATE) {
                options.url = openApi.ip + openApi.certificateTransfer
            }
            new FormSubmit(options);
        };

        var init = function() {
            // 获取回显的详细信息
            Util.getDetailData($routeParams.id, function(data) {
                $scope.param = data;
            });
            // 显示审批记录判断
            Util.showloglist($routeParams.id, function(data) {
                $scope.logData = data;
            });
        };
        // 初始化
        init();
    });
